/*----------------------------------------------------------------------
 *
 * Copyright 2009, Thomas Dejanovic.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 *
 *---------------------------------------------------------------------
 *
 * Tasks to access registers via the dcom lpcb interface.
 *
 *---------------------------------------------------------------------*/

`ifndef DCOM_UART_TASKS
 `include "dcom_uart_tasks.vh"
`endif

`ifndef LPCB_DEFINES
 `include "lpcb_defines.vh"
`endif

`ifndef DCOM_LPCB_TASKS

 `define DCOM_LPCB_TASKS

task uart_read;
  input  [31:0] a;
  output [31:0] b;
  begin
    uart_send_byte(`LPCB_READ_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_get_byte(b[31:24]);
    uart_get_byte(b[23:16]);
    uart_get_byte(b[15: 8]);
    uart_get_byte(b[ 7: 0]);
    $display("// uart_read 0x%6x from location 0x%6x",b,a);
  end
endtask // uart_read


task uart_read_08_bytes;
  input  [31:0] a;
  output [31:0] b;
  output [31:0] c;
  begin
    uart_send_byte(`LPCB_READ_08_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_get_byte(b[31:24]);
    uart_get_byte(b[23:16]);
    uart_get_byte(b[15: 8]);
    uart_get_byte(b[ 7: 0]);
    uart_get_byte(c[31:24]);
    uart_get_byte(c[23:16]);
    uart_get_byte(c[15: 8]);
    uart_get_byte(c[ 7: 0]);
    $display("// uart_read 8 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_read_08_bytes


task uart_read_16_bytes;
  input  [31:0] a;
  output [31:0] b;
  output [31:0] c;
  output [31:0] d;
  output [31:0] e;
  begin
    uart_send_byte(`LPCB_READ_16_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_get_byte(b[31:24]);
    uart_get_byte(b[23:16]);
    uart_get_byte(b[15: 8]);
    uart_get_byte(b[ 7: 0]);
    uart_get_byte(c[31:24]);
    uart_get_byte(c[23:16]);
    uart_get_byte(c[15: 8]);
    uart_get_byte(c[ 7: 0]);
    uart_get_byte(d[31:24]);
    uart_get_byte(d[23:16]);
    uart_get_byte(d[15: 8]);
    uart_get_byte(d[ 7: 0]);
    uart_get_byte(e[31:24]);
    uart_get_byte(e[23:16]);
    uart_get_byte(e[15: 8]);
    uart_get_byte(e[ 7: 0]);
    $display("// uart_read 16 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_read_16_bytes


task uart_read_32_bytes;
  input  [31:0] a;
  output [31:0] b;
  output [31:0] c;
  output [31:0] d;
  output [31:0] e;
  output [31:0] f;
  output [31:0] g;
  output [31:0] h;
  output [31:0] i;
  begin
    uart_send_byte(`LPCB_READ_32_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_get_byte(b[31:24]);
    uart_get_byte(b[23:16]);
    uart_get_byte(b[15: 8]);
    uart_get_byte(b[ 7: 0]);
    uart_get_byte(c[31:24]);
    uart_get_byte(c[23:16]);
    uart_get_byte(c[15: 8]);
    uart_get_byte(c[ 7: 0]);
    uart_get_byte(d[31:24]);
    uart_get_byte(d[23:16]);
    uart_get_byte(d[15: 8]);
    uart_get_byte(d[ 7: 0]);
    uart_get_byte(e[31:24]);
    uart_get_byte(e[23:16]);
    uart_get_byte(e[15: 8]);
    uart_get_byte(e[ 7: 0]);
    uart_get_byte(f[31:24]);
    uart_get_byte(f[23:16]);
    uart_get_byte(f[15: 8]);
    uart_get_byte(f[ 7: 0]);
    uart_get_byte(g[31:24]);
    uart_get_byte(g[23:16]);
    uart_get_byte(g[15: 8]);
    uart_get_byte(g[ 7: 0]);
    uart_get_byte(h[31:24]);
    uart_get_byte(h[23:16]);
    uart_get_byte(h[15: 8]);
    uart_get_byte(h[ 7: 0]);
    uart_get_byte(i[31:24]);
    uart_get_byte(i[23:16]);
    uart_get_byte(i[15: 8]);
    uart_get_byte(i[ 7: 0]);
    $display("// uart_read 32 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_read_32_bytes


task uart_repeat_read;
  output [31:0] b;
  begin
    uart_send_byte(`LPCB_REPEAT_READ_OPCODE);
    uart_get_byte(b[31:24]);
    uart_get_byte(b[23:16]);
    uart_get_byte(b[15: 8]);
    uart_get_byte(b[ 7: 0]);
    $display("// uart_repeat_read 0x%6x",b);
  end
endtask // uart_repeat_read

task uart_repeat_read_08_bytes;
  input  [31:0] a;
  output [31:0] b;
  output [31:0] c;
  begin
    uart_send_byte(`LPCB_REPEAT_READ_08_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_get_byte(b[31:24]);
    uart_get_byte(b[23:16]);
    uart_get_byte(b[15: 8]);
    uart_get_byte(b[ 7: 0]);
    uart_get_byte(c[31:24]);
    uart_get_byte(c[23:16]);
    uart_get_byte(c[15: 8]);
    uart_get_byte(c[ 7: 0]);
    $display("// uart_repeat_read 8 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_repeat_read_08_bytes


task uart_repeat_read_16_bytes;
  input  [31:0] a;
  output [31:0] b;
  output [31:0] c;
  output [31:0] d;
  output [31:0] e;
  begin
    uart_send_byte(`LPCB_REPEAT_READ_16_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_get_byte(b[31:24]);
    uart_get_byte(b[23:16]);
    uart_get_byte(b[15: 8]);
    uart_get_byte(b[ 7: 0]);
    uart_get_byte(c[31:24]);
    uart_get_byte(c[23:16]);
    uart_get_byte(c[15: 8]);
    uart_get_byte(c[ 7: 0]);
    uart_get_byte(d[31:24]);
    uart_get_byte(d[23:16]);
    uart_get_byte(d[15: 8]);
    uart_get_byte(d[ 7: 0]);
    uart_get_byte(e[31:24]);
    uart_get_byte(e[23:16]);
    uart_get_byte(e[15: 8]);
    uart_get_byte(e[ 7: 0]);
    $display("// uart_repeat_read 16 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_repeat_read_16_bytes


task uart_repeat_read_32_bytes;
  input  [31:0] a;
  output [31:0] b;
  output [31:0] c;
  output [31:0] d;
  output [31:0] e;
  output [31:0] f;
  output [31:0] g;
  output [31:0] h;
  output [31:0] i;
  begin
    uart_send_byte(`LPCB_REPEAT_READ_32_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_get_byte(b[31:24]);
    uart_get_byte(b[23:16]);
    uart_get_byte(b[15: 8]);
    uart_get_byte(b[ 7: 0]);
    uart_get_byte(c[31:24]);
    uart_get_byte(c[23:16]);
    uart_get_byte(c[15: 8]);
    uart_get_byte(c[ 7: 0]);
    uart_get_byte(d[31:24]);
    uart_get_byte(d[23:16]);
    uart_get_byte(d[15: 8]);
    uart_get_byte(d[ 7: 0]);
    uart_get_byte(e[31:24]);
    uart_get_byte(e[23:16]);
    uart_get_byte(e[15: 8]);
    uart_get_byte(e[ 7: 0]);
    uart_get_byte(f[31:24]);
    uart_get_byte(f[23:16]);
    uart_get_byte(f[15: 8]);
    uart_get_byte(f[ 7: 0]);
    uart_get_byte(g[31:24]);
    uart_get_byte(g[23:16]);
    uart_get_byte(g[15: 8]);
    uart_get_byte(g[ 7: 0]);
    uart_get_byte(h[31:24]);
    uart_get_byte(h[23:16]);
    uart_get_byte(h[15: 8]);
    uart_get_byte(h[ 7: 0]);
    uart_get_byte(i[31:24]);
    uart_get_byte(i[23:16]);
    uart_get_byte(i[15: 8]);
    uart_get_byte(i[ 7: 0]);
    $display("// uart_repeat_read 32 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_repeat_read_32_bytes


//======================================================================


task uart_write;
  input [31:0] a;
  input [31:0] b;
  begin
    uart_send_byte(`LPCB_WRITE_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_send_byte(b[31:24]);
    uart_send_byte(b[23:16]);
    uart_send_byte(b[15: 8]);
    uart_send_byte(b[ 7: 0]);
    $display("// uart_write 0x%6x to location 0x%6x",b,a);
  end
endtask // uart_write


task uart_write_08_bytes;
  input [31:0] a;
  input [31:0] b;
  input [31:0] c;
  begin
    uart_send_byte(`LPCB_WRITE_08_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_send_byte(b[31:24]);
    uart_send_byte(b[23:16]);
    uart_send_byte(b[15: 8]);
    uart_send_byte(b[ 7: 0]);
    uart_send_byte(c[31:24]);
    uart_send_byte(c[23:16]);
    uart_send_byte(c[15: 8]);
    uart_send_byte(c[ 7: 0]);
    $display("// uart_write 8 bytes 0x%08x, 0x%08x to location 0x%x",b,c,a);
  end
endtask // uart_write_08_bytes


task uart_write_16_bytes;
  input [31:0] a;
  input [31:0] b;
  input [31:0] c;
  input [31:0] d;
  input [31:0] e;
  begin
    uart_send_byte(`LPCB_WRITE_16_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_send_byte(b[31:24]);
    uart_send_byte(b[23:16]);
    uart_send_byte(b[15: 8]);
    uart_send_byte(b[ 7: 0]);
    uart_send_byte(c[31:24]);
    uart_send_byte(c[23:16]);
    uart_send_byte(c[15: 8]);
    uart_send_byte(c[ 7: 0]);
    uart_send_byte(d[31:24]);
    uart_send_byte(d[23:16]);
    uart_send_byte(d[15: 8]);
    uart_send_byte(d[ 7: 0]);
    uart_send_byte(e[31:24]);
    uart_send_byte(e[23:16]);
    uart_send_byte(e[15: 8]);
    uart_send_byte(e[ 7: 0]);
    $display("// uart_write 16 bytes 0x%08x, 0x%08x to location 0x%x",b,c,a);
  end
endtask // uart_write_16_bytes


task uart_write_32_bytes;
  input [31:0] a;
  input [31:0] b;
  input [31:0] c;
  input [31:0] d;
  input [31:0] e;
  input [31:0] f;
  input [31:0] g;
  input [31:0] h;
  input [31:0] i;
  begin
    uart_send_byte(`LPCB_WRITE_32_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_send_byte(b[31:24]);
    uart_send_byte(b[23:16]);
    uart_send_byte(b[15: 8]);
    uart_send_byte(b[ 7: 0]);
    uart_send_byte(c[31:24]);
    uart_send_byte(c[23:16]);
    uart_send_byte(c[15: 8]);
    uart_send_byte(c[ 7: 0]);
    uart_send_byte(d[31:24]);
    uart_send_byte(d[23:16]);
    uart_send_byte(d[15: 8]);
    uart_send_byte(d[ 7: 0]);
    uart_send_byte(e[31:24]);
    uart_send_byte(e[23:16]);
    uart_send_byte(e[15: 8]);
    uart_send_byte(e[ 7: 0]);
    uart_send_byte(f[31:24]);
    uart_send_byte(f[23:16]);
    uart_send_byte(f[15: 8]);
    uart_send_byte(f[ 7: 0]);
    uart_send_byte(g[31:24]);
    uart_send_byte(g[23:16]);
    uart_send_byte(g[15: 8]);
    uart_send_byte(g[ 7: 0]);
    uart_send_byte(h[31:24]);
    uart_send_byte(h[23:16]);
    uart_send_byte(h[15: 8]);
    uart_send_byte(h[ 7: 0]);
    uart_send_byte(i[31:24]);
    uart_send_byte(i[23:16]);
    uart_send_byte(i[15: 8]);
    uart_send_byte(i[ 7: 0]);
    $display("// uart_write 32 bytes 0x%08x, 0x%08x to location 0x%x",b,c,a);
  end
endtask // uart_write_32_bytes


task uart_repeat_write;
  input [31:0] b;
  begin
    uart_send_byte(`LPCB_REPEAT_WRITE_OPCODE);
    uart_send_byte(b[31:24]);
    uart_send_byte(b[23:16]);
    uart_send_byte(b[15: 8]);
    uart_send_byte(b[ 7: 0]);
    $display("// uart_repeat_write 0x%6x",b);
  end
endtask // uart_repeat_write

task uart_repeat_write_08_bytes;
  input [31:0] a;
  input [31:0] b;
  input [31:0] c;
  begin
    uart_send_byte(`LPCB_REPEAT_WRITE_08_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_send_byte(b[31:24]);
    uart_send_byte(b[23:16]);
    uart_send_byte(b[15: 8]);
    uart_send_byte(b[ 7: 0]);
    uart_send_byte(c[31:24]);
    uart_send_byte(c[23:16]);
    uart_send_byte(c[15: 8]);
    uart_send_byte(c[ 7: 0]);
    $display("// uart_repeat_write 8 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_repeat_write_08_bytes


task uart_repeat_write_16_bytes;
  input [31:0] a;
  input [31:0] b;
  input [31:0] c;
  input [31:0] d;
  input [31:0] e;
  begin
    uart_send_byte(`LPCB_REPEAT_WRITE_16_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_send_byte(b[31:24]);
    uart_send_byte(b[23:16]);
    uart_send_byte(b[15: 8]);
    uart_send_byte(b[ 7: 0]);
    uart_send_byte(c[31:24]);
    uart_send_byte(c[23:16]);
    uart_send_byte(c[15: 8]);
    uart_send_byte(c[ 7: 0]);
    uart_send_byte(d[31:24]);
    uart_send_byte(d[23:16]);
    uart_send_byte(d[15: 8]);
    uart_send_byte(d[ 7: 0]);
    uart_send_byte(e[31:24]);
    uart_send_byte(e[23:16]);
    uart_send_byte(e[15: 8]);
    uart_send_byte(e[ 7: 0]);
    $display("// uart_repeat_write 16 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_repeat_write_16_bytes


task uart_repeat_write_32_bytes;
  input [31:0] a;
  input [31:0] b;
  input [31:0] c;
  input [31:0] d;
  input [31:0] e;
  input [31:0] f;
  input [31:0] g;
  input [31:0] h;
  input [31:0] i;
  begin
    uart_send_byte(`LPCB_REPEAT_WRITE_32_OPCODE);
    uart_send_byte(a[31:24]);
    uart_send_byte(a[23:16]);
    uart_send_byte(a[15: 8]);
    uart_send_byte(a[ 7: 0]);
    uart_send_byte(b[31:24]);
    uart_send_byte(b[23:16]);
    uart_send_byte(b[15: 8]);
    uart_send_byte(b[ 7: 0]);
    uart_send_byte(c[31:24]);
    uart_send_byte(c[23:16]);
    uart_send_byte(c[15: 8]);
    uart_send_byte(c[ 7: 0]);
    uart_send_byte(d[31:24]);
    uart_send_byte(d[23:16]);
    uart_send_byte(d[15: 8]);
    uart_send_byte(d[ 7: 0]);
    uart_send_byte(e[31:24]);
    uart_send_byte(e[23:16]);
    uart_send_byte(e[15: 8]);
    uart_send_byte(e[ 7: 0]);
    uart_send_byte(f[31:24]);
    uart_send_byte(f[23:16]);
    uart_send_byte(f[15: 8]);
    uart_send_byte(f[ 7: 0]);
    uart_send_byte(g[31:24]);
    uart_send_byte(g[23:16]);
    uart_send_byte(g[15: 8]);
    uart_send_byte(g[ 7: 0]);
    uart_send_byte(h[31:24]);
    uart_send_byte(h[23:16]);
    uart_send_byte(h[15: 8]);
    uart_send_byte(h[ 7: 0]);
    uart_send_byte(i[31:24]);
    uart_send_byte(i[23:16]);
    uart_send_byte(i[15: 8]);
    uart_send_byte(i[ 7: 0]);
    $display("// uart_repeat_write 32 bytes 0x%08x, 0x%08x from location 0x%x",b,c,a);
  end
endtask // uart_repeat_write_32_bytes



`endif //  `ifndef DCOM_LPCB_TASKS

/*----------------------------------------------------------------*/

// Local Variables:
// mode: verilog
// End:
